﻿<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../config/connect.php");
require_once("../public/common.php");
// ring_login();

if( !HasLogin() ) 
{
	$url = "Location:login.php?ref=reset_paw.php";
	header($url);
}

$email = $_SESSION["email"];
$userid = $_SESSION["userid"];
$nickname = $_SESSION["nickname"];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?PHP echo $nickname; ?>家的宝贝 - 兔丝街</title>
<link type="text/css" rel="stylesheet" href="../css/base.css" />
<link type="text/css" rel="stylesheet" href="../css/person.css" />
<script type="text/javascript" src="../js/jquery-1.4.4.js"></script>
<script type="text/javascript">
function Reset_Password(){
	var OldPaw = $("#Old_Paw").val();
	var NewPaw = $("#New_Paw").val();
	var ConPaw = $("#Con_Paw").val();
	$('.edit_div .s3').hide();
	if(OldPaw.length == 0){
		//$('.edit_div .s3').hide();
		$('.Old_Paw').html("<span style='color:red;'>原始密码不能为空</span>");
		$('.Old_Paw').show();
        return false;
	}
	if(NewPaw.length == 0){
		//$('.edit_div .s3').hide();
		$('.New_Paw').html("<span style='color:red;'>请输入你的新密码</span>");
		$('.New_Paw').show();
        return false;
	}
	if(NewPaw.length < 6 || NewPaw.length > 12){
		//$('.edit_div .s3').hide();
		$('.New_Paw').html("<span style='color:red;'>对不起，请输入6~12位数字与英文字符</span>");
		$('.New_Paw').show();
        return false;
	}
	if (NewPaw != ConPaw) {
		//$('.edit_div .s3').hide();
    	$('.Con_Paw').html("<span style='color:red;'>两次输入的密码不一致</span>");
    	$('.Con_Paw').show();
     	return false;
     }
	 
	return true;
}
</script>
</head>

<?PHP
if(isset($_POST["submit"])){
	$OldPaw=md5(trim(GetPostParamStr("Old_Paw")));
	$NewPaw=md5(trim(GetPostParamStr("New_Paw")));
	$ConPaw=md5(trim(GetPostParamStr("Con_Paw")));

	if($OldPaw != "" && $NewPaw != "" && $ConPaw != "" && $NewPaw==$ConPaw) {
   		$sql="select * from tsj_user where id='$userid'";
   		$result=mysql_query($sql);

   		if(mysql_num_rows($result) > 0) {
			$row = mysql_fetch_assoc( $result );
			if($OldPaw == $row['password']) {
				$sql="update tsj_user set password='$NewPaw' where id='$userid'";
				mysql_query($sql);
				echo "<script>alert('密码修改成功！');</script>";
			}else{
				echo "<script>alert('原密码错误，请您重新出入！');</script>";
			}
		}
	}
}
?>

<body class="bGerenxx">
<div id="wrapper">
<!---head kaishi--->
     <?php
		include("../headtop.php"); 
	?>
<!-----head 结束----->
    <div id="main" class="person">
    	<!---左侧开始--->
    	<div class="grid_3">
        	<div class="person_left">
            	<div class="person_info">
                    <!---侧栏导航 kaishi--->
					<?php
                    	include("sidebarnav.php"); 
                    ?>
                    <!------------>
                </div>            	
            </div>
        </div>
 
         <!---右侧--->
      	<div class="grid_9"> 
        	<div id="editGoods">
            <div class="edit_left Personal">
                <div class="Per">
                	<ul>

                		<li><a href="edit.php">我的资料</a></li>
                        <li><a href="avatar_edit.php">上传/编辑头像</a></li>
                        <li class="as"><a href="reset_paw.php">修改密码</a></li>
                    </ul>
                </div>
                <form id="resetpawForm" action="" method="post" onsubmit="return Reset_Password();">
                    <div class="edit_div">

                        <div class="s1">原密码：</div>
                        <div class="s2"><input type="password" size="70" name="Old_Paw" id="Old_Paw" height="20" value="" /></div>
                        <div class="s3 Old_Paw" id="Old_Paw"></div>
                    </div>
                    <div style="padding-left:90px; margin-bottom:10px;"><div class="s2" id="ishasitem"></div></div>
                    <div class="edit_div">
                        <div class="s1">新密码：</div>
                        <div class="s2"><input type="password" size="70" name="New_Paw" id="New_Paw" height="20" value="" /></div>
						<div class="s3 New_Paw"></div>
                    </div>
                    <div class="edit_div">
                        <div class="s1">确认密码：</div>
                        <div class="s2"><input type="password" size="70" height="20" name="Con_Paw" id="Con_Paw" value="" /></div>
                        <div class="s3 Con_Paw"></div>
                    </div>
                    <div class="edit_div">
                        <div class="btn"><input type="submit" name="submit" value="确认" class="ed_h" style=" width:80px;" /></div>
                    </div>
                </form>
            </div>

        	</div>          
        </div>
    </div>
</div>
<!---网尾 kaishi--->
 <?php
     include("../networkend.php"); 
?>
<!------------>
</body>
</html>

<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F22b7662ec7d02c816ddfd8f6df6e5cea' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20984072-3']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>